﻿using Caviar.Core.Services.IMServices;
using Caviar.Infrastructure.Attributes;
using Caviar.SharedKernel.Entities;
using Caviar.SharedKernel.Template.View.IM;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Caviar.Infrastructure.API
{
    public partial class UserController
    {

        private readonly IMServices  _imServices;
        public UserController(IMServices imServices)
        {
            _imServices = imServices;
        }

        [HttpPost]
        public async Task<IActionResult> RegisterAsync(RegisterModel model)
        {
            return Ok(await _imServices.RegisterAsync(model));
        }

        [HttpPost]
        public async Task<IActionResult> LoginAsync(string userName, string password)
        {
            return Ok(await _imServices.LoginAsync(userName, password));
        }

        [HttpPost]
        [AuthorizeVerify]
        public async Task<IActionResult> AddFriendByUserNameAsync(string userName, string messages) 
        {
            return Ok(await _imServices.AddFriendByUserNameAsync(userName, messages));
        }

        [HttpPost]
        [AuthorizeVerify]
        public async Task<IActionResult> HandleFriendRequestAsync(string userName, FriendStatusType status)
        {
            return Ok(await _imServices.HandleFriendRequestAsync(userName, status));
        }

        [HttpPost]
        [AuthorizeVerify]
        public async Task<IActionResult> GetMyFriendsAsync( string search)
        {
            return Ok(await _imServices.GetMyFriendsAsync(search));
        }
    }
}
